# Contributor: Grigory Kirillov <txgk@bk.ru>
# Maintainer: Celeste <cielesti@protonmail.com>
maintainer="Celeste <cielesti@protonmail.com>"
pkgname=singular
pkgver=4.4.0
pkgrel=0
_pkgbase="${pkgver%%_p*}"
pkgdesc="Computer algebra system for polynomial computations"
url="https://www.singular.uni-kl.de/"
# s390x: blocked by flint-dev
arch="all !s390x"
license="GPL-2.0-only OR GPL-3.0-only"
depends="python3"
makedepends="
	cddlib-dev
	gmp-dev
	flint-dev
	perl
	"
subpackages="
	$pkgname-static
	$pkgname-dev
	$pkgname-emacs::noarch
	$pkgname-doc
	"
source="https://www.singular.uni-kl.de/ftp/pub/Math/Singular/SOURCES/${_pkgbase//./-}/singular-${pkgver/_p/p}.tar.gz"

build() {
	export CXXFLAGS="${CXXFLAGS/-Os/-O3}" # gotta go fast

	./configure \
		--target=$CTARGET \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--libexecdir=/usr/lib \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--enable-bigintm-module \
		--enable-Order-module \
		--enable-python-module \
		--enable-gfanlib-module \
		--enable-polymake-module
	make
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" install
	# Perhaps it is better to get rid of 36mb of HTML and images.
	rm -rf "$pkgdir"/usr/share/doc
}

dev() {
	pkgdesc="$pkgdesc (development files)"

	amove \
		usr/bin/libpolys-config \
		usr/bin/libsingular-config \
		usr/include \
		usr/lib/pkgconfig \
		usr/lib/libSingular.so \
		usr/lib/libfactory.so \
		usr/lib/libomalloc.so \
		usr/lib/libpolys.so \
		usr/lib/libsingular_resources.so
}

emacs() {
	pkgdesc="Emacs plugins for $pkgname"

	amove usr/share/singular/emacs
}

sha512sums="
d12552a18859bbd51dd5ee9728aedcf79442c37de1f600efdde274f54d655b181a4f08337368c18d39713b419ff87f7e0ae331e7f8ff892150c9ddb3a2a7d6d3  singular-4.4.0.tar.gz
"
